package task

/*
这里的数据结构是给api使用的，如果对外接口不变，不要修改。
*/

type StorageType uint32

const (
	StoreInTos StorageType = iota
	StoreInS3
)

type TranscodeMode uint32

const (
	Statistic TranscodeMode = iota
	Dynamic
)

type Priority uint32

const (
	NonRealtime Priority = iota
	RealTime
)

type TaskStatus uint32

const (
	Submited TaskStatus = iota
	Running
	Done
	Failed
)

type InputFormat = uint32

const (
	InputFormatUnknown = iota
	InputFormatPPT
	InputFormatPPTX
	InputFormatDOC
	InputFormatDOCX
	InputFormatPDF
)

type OutputFormat = uint32

const (
	OutputFormatUnknown = iota
	OutputFormatPNG
	OutputFormatJPEG
	OutputFormatWEBP
)

const (
	DefaultOutputWidth     = 1280
	DefaultOutputHeight    = 720
	DefaultThumbnailWidth  = 320
	DefaultThumbnailHeight = 180
)

type TranscodeConfig struct {
	ForceUseResolution bool         `json:"force_use_resolution"`
	InputFormat        InputFormat  `json:"input_format"`
	OutputFormat       OutputFormat `json:"output_format"`
	OutputWidth        int          `json:"output_width"`
	OutputHeight       int          `json:"output_height"`
	Thumbnail          bool         `json:"thumbnail"`
	ThumbnailWidth     int          `json:"thumbnail_width"`
	ThumbnailHeight    int          `json:"thumbnail_height"`
}

type ResourceAttr struct {
	FileName string `json:"file_name"`
	Size     int    `json:"size"`
}

func (c *TranscodeConfig) GetOutputFormat() string {
	switch c.OutputFormat {
	case OutputFormatJPEG:
		return "jpeg"
	case OutputFormatPNG:
		return "png"
	}
	return ""
}

func (c *TranscodeConfig) GetInputFormat() string {
	switch c.InputFormat {
	case InputFormatPPT:
		return "ppt"
	case InputFormatPPTX:
		return "pptx"
	case InputFormatDOC:
		return "doc"
	case InputFormatDOCX:
		return "docx"
	case InputFormatPDF:
		return "pdf"
	}
	return ""
}

type StorageConfig struct {
	Type         StorageType  `json:"type"`
	TosConfig    TosConfig    `json:"tos_config"`
	CustomConfig CustomConfig `json:"custom_config"`
}

type TosConfig struct {
	AccountId string `json:"account_id"`
	Region    uint32 `json:"region"`
	Bucket    string `json:"bucket"`
}

type CustomConfig struct {
	Vendor    uint32 `json:"vendor"`
	Region    uint32 `json:"region"`
	Bucket    string `json:"bucket"`
	AccessKey string `json:"access_key"`
	SecretKey string `json:"secret_key"`
}
